package com.exam.controller;

import com.exam.pojo.Message;
import com.exam.service.MessageService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;



@RestController
public class MessageController {

    @Resource
    private MessageService messageService;

    @GetMapping("/messages/{pageNum}/{pageSize}")
    public PageInfo<Message> findAllPage(
            @PathVariable("pageNum") Integer pageNum,
            @PathVariable("pageSize") Integer pageSize) {
        return messageService.queryPage(pageNum,pageSize);
    }
    @GetMapping("/messages/{pageNum}/{pageSize}/{id}")
    public PageInfo<Message> findByIdPage(
            @PathVariable("pageNum") Integer pageNum,
            @PathVariable("pageSize") Integer pageSize,
            @PathVariable("id") Integer studentId) {
        return messageService.queryPageByStudentId(pageNum,pageSize,studentId);
    }
    @GetMapping("/messages/{id}")
    public Message findAll(@PathVariable("id") Integer id) {
        return messageService.queryById(id);
    }

    @PostMapping("/message/add")
    public int add(@RequestBody Message message){
        return messageService.add(message);
    }
    @PutMapping("/message/update")
    public int update(@RequestBody Message message){
        return messageService.updateById(message);
    }

    @DeleteMapping("/message/detele/{id}")
    public int detele(@PathVariable("id") Integer id){
        return messageService.deteleById(id);
    }
}
